import {
    cMap, CView, CFill,
    CStyle, CStroke, Cget,
    CVectorLayer, CVector,
    CSelect, Cclick, CDraw,
    createBox, CLcontrol,
} from "./ol";
import { mouseLngLat } from "./ol/tools";


export default class Mapol {
    id;
    layers;
    zoom;
    coordinates;
    projection;
    constructor(
        { id, layers, coordinates, projection, zoom }
    ) {
        this.id = id;
        this.layers = layers;
        this.coordinates = coordinates;
        this.projection = projection;
        this.zoom = zoom;
    }
    /**
     * 地图初始化
     */
    map = () => {
        return new cMap({
            controls: CLcontrol.defaults({
                zoom: false,
                rotate: false,
                attribution: false
            }),
            view: new CView({
                center: this.coordinates || [119.816845073, 28.431519928, 64],
                projection: this.projection || Cget("EPSG:4326"),  //指定投影采用4326坐标系 119.91028, 28.40652
                zoom: this.zoom || 10.9
            }),
            target: this.id,

        });
    }
    /**
     * 更新视角
     * @param {*} map 
     * @param {*} center 
     * @param {*} zoom 
     * @param {*} duration 
     */
    static setView = (map, center, zoom = 18, duration = 8000) => {
        map.getView().animate({
            center,
            zoom,
            duration,
        })
    }

}